<?php

namespace app\admin\model;

use think\Model;


class Job extends Model
{

    

    

    // 表名
    protected $name = 'job';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'add_time_text',
        'createtime_text',
        'updatetime_text',
    ];
    public function getCreatetimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['createtime']);
    }
    public function getUpdatetimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['updatetime']);
    }

    



    public function getAddTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setAddTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function groupAndCount($field,$limit)
    {
       $sql="select count(*) as tpcount ,$field,title,companey_name,id from ".$this->getTable()." where $field is not null  group by $field order by tpcount desc limit $limit";
       return $this->query($sql);

    }


}
